package com.xxl.job.executor.common.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class CommonUtil {

	/**
	 * 按指定大小，分隔集合，将集合按规定个数分为n个部分
	 * @param <T>
	 *
	 * @param list
	 * @param len
	 * @return
	 */
	public static <T> List<List<T>> splitList(List<T> list, int len) {

		if (list == null || list.isEmpty() || len < 1) {
			return Collections.emptyList();
		}

		List<List<T>> result = new ArrayList<>();

		int size = list.size();
		int count = (size + len - 1) / len;

		for (int i = 0; i < count; i++) {
			List<T> subList = list.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
			result.add(subList);
		}

		return result;
	}

	public static int String_length(String value) {
		int valueLength = 0;
		String chinese = "[\u4e00-\u9fa5]";
		for (int i = 0; i < value.length(); i++) {
			String temp = value.substring(i, i + 1);
			if (temp.matches(chinese)) {
				valueLength += 2;
			} else {
				valueLength += 1;
			}
		}
		return valueLength;
	}
}